package org.apache.rocketmq.remoting.netty;

import org.apache.rocketmq.remoting.common.TlsMode;

import static org.apache.rocketmq.remoting.netty.TlsSystemConfig.TLS_ENABLE;

/**
 * @课程描述:从零带你写框架系列中的课程，整个系列包含netty，xxl-job，rocketmq，nacos，sofajraft，spring，springboot，disruptor，编译器，虚拟机等等。
 * @author：陈清风扬，个人微信号：chenqingfengyangjj。
 * @date:2025/1/6
 * @方法描述：该类的对象封装了Netty构建的客户端要用到的所有配置参数，我就不给这个类添加注释信息了，大家可以直接阅读NettyRemotingClient类的代码
 * NettyRemotingClient类中的注释非常详细，每一次要从NettyClientConfig类中获得某个配置信息的时候，我都添加了详细注释，解释要获得的这个配置信息的作用
 */
public class NettyClientConfig {


    private int clientWorkerThreads = NettySystemConfig.clientWorkerSize;


    private int clientCallbackExecutorThreads = Runtime.getRuntime().availableProcessors();


    private int clientOnewaySemaphoreValue = NettySystemConfig.CLIENT_ONEWAY_SEMAPHORE_VALUE;


    private int clientAsyncSemaphoreValue = NettySystemConfig.CLIENT_ASYNC_SEMAPHORE_VALUE;


    private int connectTimeoutMillis = NettySystemConfig.connectTimeoutMillis;


    private long channelNotActiveInterval = 1000 * 60;


    private int clientChannelMaxIdleTimeSeconds = NettySystemConfig.clientChannelMaxIdleTimeSeconds;


    private int clientSocketSndBufSize = NettySystemConfig.socketSndbufSize;


    private int clientSocketRcvBufSize = NettySystemConfig.socketRcvbufSize;


    private boolean clientPooledByteBufAllocatorEnable = false;


    private boolean clientCloseSocketIfTimeout = NettySystemConfig.clientCloseSocketIfTimeout;


    private boolean useTLS = Boolean.parseBoolean(System.getProperty(TLS_ENABLE,
            String.valueOf(TlsSystemConfig.tlsMode == TlsMode.ENFORCING)));


    private String socksProxyConfig = "{}";


    private int writeBufferHighWaterMark = NettySystemConfig.writeBufferHighWaterMark;


    private int writeBufferLowWaterMark = NettySystemConfig.writeBufferLowWaterMark;


    private boolean disableCallbackExecutor = false;


    private boolean disableNettyWorkerGroup = false;


    private long maxReconnectIntervalTimeSeconds = 60;


    private boolean enableReconnectForGoAway = true;


    private boolean enableTransparentRetry = true;


    public boolean isClientCloseSocketIfTimeout() {
        return clientCloseSocketIfTimeout;
    }


    public void setClientCloseSocketIfTimeout(final boolean clientCloseSocketIfTimeout) {
        this.clientCloseSocketIfTimeout = clientCloseSocketIfTimeout;
    }


    public int getClientWorkerThreads() {
        return clientWorkerThreads;
    }


    public void setClientWorkerThreads(int clientWorkerThreads) {
        this.clientWorkerThreads = clientWorkerThreads;
    }


    public int getClientOnewaySemaphoreValue() {
        return clientOnewaySemaphoreValue;
    }


    public void setClientOnewaySemaphoreValue(int clientOnewaySemaphoreValue) {
        this.clientOnewaySemaphoreValue = clientOnewaySemaphoreValue;
    }


    public int getConnectTimeoutMillis() {
        return connectTimeoutMillis;
    }


    public void setConnectTimeoutMillis(int connectTimeoutMillis) {
        this.connectTimeoutMillis = connectTimeoutMillis;
    }


    public int getClientCallbackExecutorThreads() {
        return clientCallbackExecutorThreads;
    }


    public void setClientCallbackExecutorThreads(int clientCallbackExecutorThreads) {
        this.clientCallbackExecutorThreads = clientCallbackExecutorThreads;
    }


    public long getChannelNotActiveInterval() {
        return channelNotActiveInterval;
    }


    public void setChannelNotActiveInterval(long channelNotActiveInterval) {
        this.channelNotActiveInterval = channelNotActiveInterval;
    }

    public int getClientAsyncSemaphoreValue() {
        return clientAsyncSemaphoreValue;
    }


    public void setClientAsyncSemaphoreValue(int clientAsyncSemaphoreValue) {
        this.clientAsyncSemaphoreValue = clientAsyncSemaphoreValue;
    }


    public int getClientChannelMaxIdleTimeSeconds() {
        return clientChannelMaxIdleTimeSeconds;
    }


    public void setClientChannelMaxIdleTimeSeconds(int clientChannelMaxIdleTimeSeconds) {
        this.clientChannelMaxIdleTimeSeconds = clientChannelMaxIdleTimeSeconds;
    }


    public int getClientSocketSndBufSize() {
        return clientSocketSndBufSize;
    }


    public void setClientSocketSndBufSize(int clientSocketSndBufSize) {
        this.clientSocketSndBufSize = clientSocketSndBufSize;
    }


    public int getClientSocketRcvBufSize() {
        return clientSocketRcvBufSize;
    }


    public void setClientSocketRcvBufSize(int clientSocketRcvBufSize) {
        this.clientSocketRcvBufSize = clientSocketRcvBufSize;
    }


    public boolean isClientPooledByteBufAllocatorEnable() {
        return clientPooledByteBufAllocatorEnable;
    }


    public void setClientPooledByteBufAllocatorEnable(boolean clientPooledByteBufAllocatorEnable) {
        this.clientPooledByteBufAllocatorEnable = clientPooledByteBufAllocatorEnable;
    }


    public boolean isUseTLS() {
        return useTLS;
    }


    public void setUseTLS(boolean useTLS) {
        this.useTLS = useTLS;
    }


    public int getWriteBufferLowWaterMark() {
        return writeBufferLowWaterMark;
    }


    public void setWriteBufferLowWaterMark(int writeBufferLowWaterMark) {
        this.writeBufferLowWaterMark = writeBufferLowWaterMark;
    }


    public int getWriteBufferHighWaterMark() {
        return writeBufferHighWaterMark;
    }


    public void setWriteBufferHighWaterMark(int writeBufferHighWaterMark) {
        this.writeBufferHighWaterMark = writeBufferHighWaterMark;
    }


    public boolean isDisableCallbackExecutor() {
        return disableCallbackExecutor;
    }


    public void setDisableCallbackExecutor(boolean disableCallbackExecutor) {
        this.disableCallbackExecutor = disableCallbackExecutor;
    }


    public boolean isDisableNettyWorkerGroup() {
        return disableNettyWorkerGroup;
    }


    public void setDisableNettyWorkerGroup(boolean disableNettyWorkerGroup) {
        this.disableNettyWorkerGroup = disableNettyWorkerGroup;
    }


    public long getMaxReconnectIntervalTimeSeconds() {
        return maxReconnectIntervalTimeSeconds;
    }


    public void setMaxReconnectIntervalTimeSeconds(long maxReconnectIntervalTimeSeconds) {
        this.maxReconnectIntervalTimeSeconds = maxReconnectIntervalTimeSeconds;
    }


    public boolean isEnableReconnectForGoAway() {
        return enableReconnectForGoAway;
    }


    public void setEnableReconnectForGoAway(boolean enableReconnectForGoAway) {
        this.enableReconnectForGoAway = enableReconnectForGoAway;
    }


    public boolean isEnableTransparentRetry() {
        return enableTransparentRetry;
    }


    public void setEnableTransparentRetry(boolean enableTransparentRetry) {
        this.enableTransparentRetry = enableTransparentRetry;
    }


    public String getSocksProxyConfig() {
        return socksProxyConfig;
    }

    public void setSocksProxyConfig(String socksProxyConfig) {
        this.socksProxyConfig = socksProxyConfig;
    }
}
